home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / hurd / hurdinit.c < prev    next >
C/C++ Source or Header  |  1994-05-25  |  5KB  |  141 lines

  1. /* Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <sys/stat.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <unistd.h>
  23. #include <hurd.h>
  24. #include <hurd/port.h>
  25. #include "set-hooks.h"
  26. #include "hurdmalloc.h"        /* XXX */
  27.  
  28.  
  29. struct hurd_port *_hurd_ports;
  30. unsigned int _hurd_nports;
  31. mode_t _hurd_umask;
  32.  
  33. void _hurd_proc_init (char **argv);
  34.  
  35. DEFINE_HOOK (_hurd_subinit, (void));
  36.  
  37. /* Initialize the library data structures from the
  38.    ints and ports passed to us by the exec server.
  39.  
  40.    PORTARRAY and INTARRAY are vm_deallocate'd.  */
  41.  
  42. void
  43. _hurd_init (int flags, char **argv,
  44.         mach_port_t *portarray, size_t portarraysize,
  45.         int *intarray, size_t intarraysize)
  46. {
  47.   int i;
  48.  
  49.   _hurd_ports = malloc (portarraysize * sizeof (*_hurd_ports));
  50.   if (_hurd_ports == NULL)
  51.     __libc_fatal ("Can't allocate _hurd_ports\n");
  52.   _hurd_nports = portarraysize;
  53.  
  54.   /* See what ports we were passed.  */
  55.   for (i = 0; i < portarraysize; ++i)
  56.     _hurd_port_init (&_hurd_ports[i], portarray[i]);
  57.  
  58.   /* When the user asks for the bootstrap port,
  59.      he will get the one the exec server passed us.  */
  60.   __task_set_special_port (__mach_task_self (), TASK_BOOTSTRAP_PORT,
  61.                portarray[INIT_PORT_BOOTSTRAP]);
  62.  
  63.   /* Tell the proc server we exist, if it does.  */
  64.   if (portarray[INIT_PORT_PROC] != MACH_PORT_NULL)
  65.     _hurd_proc_init (argv);
  66.  
  67.   if (intarraysize > INIT_UMASK)
  68.     _hurd_umask = intarray[INIT_UMASK] & 0777;
  69.   else
  70.     _hurd_umask = CMASK;
  71.  
  72.   /* All done with init ints and ports.  */
  73.   __vm_deallocate (__mach_task_self (),
  74.            (vm_address_t) intarray,
  75.            intarraysize * sizeof (int));
  76.   __vm_deallocate (__mach_task_self (),
  77.            (vm_address_t) portarray,
  78.            portarraysize * sizeof (mach_port_t));
  79.  
  80.   if (flags & EXEC_SECURE)
  81.     /* XXX if secure exec, elide environment variables
  82.        which the library uses and could be security holes.
  83.        CORESERVER, COREFILE
  84.        */ ;
  85.  
  86.   /* Call other things which want to do some initialization.  These are not
  87.      on the __libc_subinit hook because things there like to be able to
  88.      assume the availability of the POSIX.1 services we provide.  */
  89.   RUN_HOOK (_hurd_subinit, ());
  90. }
  91.  
  92. #include <hurd/signal.h>
  93.  
  94. /* The user can do "int _hide_arguments = 1;" to make
  95.    sure the arguments are never visible with `ps'.  */
  96. int _hide_arguments, _hide_environment;
  97.  
  98. /* Hook for things which should be initialized as soon as the proc
  99.    server is available.  */
  100. DEFINE_HOOK (_hurd_proc_subinit, (void));
  101.  
  102. /* Do startup handshaking with the proc server just installed in _hurd_ports.
  103.    Call _hurdsig_init to set up signal processing.  */
  104.  
  105. void
  106. _hurd_proc_init (char **argv)
  107. {
  108.   mach_port_t oldmsg;
  109.   struct hurd_userlink ulink;
  110.   process_t procserver;
  111.  
  112.   /* Initialize the signal code; Mach exceptions will become signals.  */
  113.   _hurdsig_init ();
  114.  
  115.   /* The signal thread is now prepared to receive messages.
  116.      It is safe to give the port to the proc server.  */
  117.  
  118.   procserver = _hurd_port_get (&_hurd_ports[INIT_PORT_PROC], &ulink);
  119.  
  120.   /* Give the proc server our message port.  */
  121.   __proc_setmsgport (procserver, _hurd_msgport, &oldmsg);
  122.   if (oldmsg != MACH_PORT_NULL)
  123.     /* Deallocate the old msg port we replaced.  */
  124.     __mach_port_deallocate (__mach_task_self (), oldmsg);
  125.  
  126.   /* Tell the proc server where our args and environment are.  */
  127.   __proc_setprocargs (procserver,
  128.               _hide_arguments ? 0 : (vm_address_t) argv,
  129.               _hide_environment ? 0 : (vm_address_t) __environ);
  130.  
  131.   _hurd_port_free (&_hurd_ports[INIT_PORT_PROC], &ulink, procserver);
  132.  
  133.   /* Initialize proc server-assisted fault recovery for the signal thread.  */
  134.   _hurdsig_fault_init ();
  135.  
  136.   /* Call other things which want to do some initialization.  These are not
  137.      on the _hurd_subinit hook because things there assume that things done
  138.      here, like _hurd_pid, are already initialized.  */
  139.   RUN_HOOK (_hurd_proc_subinit, ());
  140. }
  141.